package net.tv90.bfmccore.game.impl.cq;

import net.tv90.bfmccore.game.GameUtils;
import net.tv90.bfmccore.game.view.GameModelViewHandler;
import net.tv90.bfmccore.helper.MCHHelper;
import net.tv90.bfmccore.util.Cooldown;
import net.tv90.bfmccore.util.vector.Vector3i;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;

import static net.tv90.bfmccore.helper.FactionHelper.*;

public interface IVehicleSpawnConquestArea {

    String getIndex();

    void teleport(Player player);

    boolean hasLight();

    boolean hasTank();

    boolean hasAA();

    boolean hasHeli();

    boolean hasTransHeli();

    boolean hasJet();

    boolean hasAtkJet();

    boolean hasFac();

    IVehicleSpawnConquestArea setHasTank();

    IVehicleSpawnConquestArea setHasAA();

    IVehicleSpawnConquestArea setHasHeli();

    IVehicleSpawnConquestArea setHasTransHeli();

    IVehicleSpawnConquestArea setHasJet();

    IVehicleSpawnConquestArea setHasAtkJet();

    IVehicleSpawnConquestArea setHasFac();

    IVehicleSpawnConquestArea setHasLight();

    IVehicleSpawnConquestArea setFirstLightSpawnPoint(List<Vector3i> firstLightSpawnPoint);

    IVehicleSpawnConquestArea setFirstTankSpawnPoint(List<Vector3i> firstTankSpawnPoint);

    IVehicleSpawnConquestArea setFirstAASpawnPoint(List<Vector3i> firstAASpawnPoint);

    IVehicleSpawnConquestArea setFirstHeliSpawnPoint(List<Vector3i> firstHeliSpawnPoint);

    IVehicleSpawnConquestArea setFirstTransHeliSpawnPoint(List<Vector3i> firstTransHeliSpawnPoint);

    IVehicleSpawnConquestArea setFirstJetSpawnPoint(List<Vector3i> firstJetSpawnPoint);

    IVehicleSpawnConquestArea setFirstAtkJetSpawnPoint(List<Vector3i> firstAtkJetSpawnPoint);

    IVehicleSpawnConquestArea setFirstFacSpawnPoint(List<Vector3i> firstFacSpawnPoint);

    IVehicleSpawnConquestArea setSecondLightSpawnPoint(List<Vector3i> secondLightSpawnPoint);

    IVehicleSpawnConquestArea setSecondTankSpawnPoint(List<Vector3i> secondTankSpawnPoint);

    IVehicleSpawnConquestArea setSecondAASpawnPoint(List<Vector3i> secondAASpawnPoint);

    IVehicleSpawnConquestArea setSecondHeliSpawnPoint(List<Vector3i> secondHeliSpawnPoint);

    IVehicleSpawnConquestArea setSecondTransHeliSpawnPoint(List<Vector3i> secondTransHeliSpawnPoint);

    IVehicleSpawnConquestArea setSecondJetSpawnPoint(List<Vector3i> secondJetSpawnPoint);

    IVehicleSpawnConquestArea setSecondAtkJetSpawnPoint(List<Vector3i> secondAtkJetSpawnPoint);

    IVehicleSpawnConquestArea setSecondFacSpawnPoint(List<Vector3i> secondFacSpawnPoint);

    IVehicleSpawnConquestArea setFirstLightVehicleGroup(List<String> firstLightVehicleGroup);

    IVehicleSpawnConquestArea setFirstTankVehicleGroup(List<String> firstTankVehicleGroup);

    IVehicleSpawnConquestArea setFirstAAVehicleGroup(List<String> firstAAVehicleGroup);

    IVehicleSpawnConquestArea setFirstHeliVehicleGroup(List<String> firstHeliVehicleGroup);

    IVehicleSpawnConquestArea setFirstTransHeliVehicleGroup(List<String> firstTransHeliVehicleGroup);

    IVehicleSpawnConquestArea setFirstJetVehicleGroup(List<String> firstJetVehicleGroup);

    IVehicleSpawnConquestArea setFirstAtkJetVehicleGroup(List<String> firstAtkJetVehicleGroup);

    IVehicleSpawnConquestArea setFirstFacVehicleGroup(List<String> firstFacVehicleGroup);

    IVehicleSpawnConquestArea setSecondLightVehicleGroup(List<String> secondLightVehicleGroup);

    IVehicleSpawnConquestArea setSecondTankVehicleGroup(List<String> secondTankVehicleGroup);

    IVehicleSpawnConquestArea setSecondAAVehicleGroup(List<String> secondAAVehicleGroup);

    IVehicleSpawnConquestArea setSecondHeliVehicleGroup(List<String> secondHeliVehicleGroup);

    IVehicleSpawnConquestArea setSecondTransHeliVehicleGroup(List<String> secondTransHeliVehicleGroup);

    IVehicleSpawnConquestArea setSecondJetVehicleGroup(List<String> secondJetVehicleGroup);

    IVehicleSpawnConquestArea setSecondAtkJetVehicleGroup(List<String> secondAtkJetVehicleGroup);

    IVehicleSpawnConquestArea setSecondFacVehicleGroup(List<String> secondFacVehicleGroup);

    default boolean canSelectVehicle(Player player, String vehicle) {
        //先将玩家设为步兵
        MCHHelper.setINF(player);
        //如果参数args[2]是步兵,直接打开传送菜单
        //格式：world_country_vehicle_point.yml
        String smallCase = vehicle.toLowerCase();
        if (vehicle.equals("inf")) {
            GameUtils.vehicleDeploy(player);
        }
        //如果参数args[2]是载具，先检查载具名额是否已满，然后检查冷却，最后设定权限并打开面板
        else {
            String faction_vehicle = getCountry2(player) + "_" + vehicle.toUpperCase();
            //检查队伍的载具名额
            int count = 0;
            List<String> list = new ArrayList<>();
            for (Player p : getTeammates(player)) {
                if (p.hasPermission("bfmc.driver." + smallCase)) {
                    list.add(p.getName());
                    count++;
                }
            }
            //如果名额已满
            if (count >= MCHHelper.getVehicleLimit(vehicle)) {
                player.sendMessage("§e[管理员]" + MCHHelper.getVehicle_Lang(vehicle) + "载具名额已满，请等待玩家" + list + "离开" + MCHHelper.getVehicle_Lang(vehicle));
                GameModelViewHandler.getInstance().createInfoGui(player, MCHHelper.getVehicle_Lang(vehicle) + "名额已满，请等待玩家" + list + "离开" + MCHHelper.getVehicle_Lang(vehicle)
                        , GameModelViewHandler.getInstance()::createMainGUI);
                return false;
            }
            //如果有空余名额
            else {
                //如果处于冷却状态
                if (Cooldown.isCool(faction_vehicle, player)) {
                    player.sendMessage("§e[管理员]" + MCHHelper.getVehicle_Lang(vehicle) + "冷却时间剩余" + Cooldown.getTime(faction_vehicle, player) + "秒");
                    GameModelViewHandler.getInstance().createInfoGui(player, MCHHelper.getVehicle_Lang(vehicle) + "冷却时间剩余" + Cooldown.getTime(faction_vehicle, player) + "秒"
                            , GameModelViewHandler.getInstance()::createMainGUI);
                    return false;
                }
                //如果单个玩家未处于冷却状态,设定权限并打开载具面板
                else {
                    for (Player teamer : getTeamer(player)) {
                        teamer.sendMessage("§a[队伍]队友" + player.getName() + "选择了" + MCHHelper.getVehicle_Lang(vehicle));
                    }
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "lp user " + player.getName() + " permission set bfmc.driver." + smallCase);
                    //GameManager.getInstance().currentGame.addVehicle(player, vehicle);
                }
            }
        }
        return true;
    }

}
